<template>
  <el-form class="right-event-push">
    <input-normal type="number" label="每天每个用户限制数" v-model="wbData.day_limit"  @change="onUpdateWbComponent"></input-normal>
    <el-divider content-position="center">分享内容设置</el-divider>
    
    <switch-normal v-model="wbData.isReplaceShareData" label="替换动态图片" @change="onUpdateWbComponent"></switch-normal>
    <switch-normal v-model="wbAttr.isRandom" label="多博文分享" @change="onChangeWbAttr"></switch-normal>
    <switch-normal v-model="wbData.isSame" label="UI与发博图片是否相同" @change="onUpdateWbComponent"></switch-normal>
    <div v-if="wbAttr.isRandom">
      <switch-normal label="多博文随机分享" v-model="wbData.isRandomPush" @change="onUpdateWbComponent"></switch-normal>
      <switch-normal v-if="wbData.isRandomPush" v-model="wbData.isGiveOther" label="提供数据给关联组件" @change="onUpdateWbComponent"></switch-normal>
      <switch-normal v-else v-model="wbData.isGetOther" label="获取组件提供数据" @change="onUpdateWbComponent"></switch-normal>
      <input-normal v-if="wbData.isGiveOther || wbData.isGetOther" label="关联组件id" v-model="wbData.relateCompId"  @change="onUpdateWbComponent"></input-normal>
      <el-button type="primary"  @click.stop="onAddWbItem" class="margin-bottom-10 margin-left-right-16"><el-icon><i class="jy-icon-plus"></i></el-icon>增加内容</el-button>
      <el-collapse v-model="activeNames">
        <el-collapse-item v-for="(item, index) in eventWbLists" :name="index+1" :key="index">
            <template #title>
            随机内容{{index+1}}<i class="jy-icon-delete el-collapse-item__arrow" @click.stop="onDeleteWbItem($event, index)"></i>
          </template>
          <textarea-normal class="margin-top-10" label="发博文本" placeholder="请在此处输入要分享的博文内容" v-model="item.text" @change="onUpdateWbItem(index)"></textarea-normal>
          <input-normal label="分享博文mid" v-model="item.mid"  @change="onUpdateWbItem(index)"></input-normal>
          <switch-normal v-model="item.isPic" label="博文带图片" @change="onUpdateWbItem(index)"></switch-normal>
          <div v-if="item.isPic">
            <switch-normal v-model="item.isRandomPic" label="随机转发一个博文图片" @change="onUpdateWbItem(0)"></switch-normal>
            <!-- <div v-for="(picItem) in item.pics" :key="picItem.pic_id">
              <input-normal label="分享url" v-model="picItem.pic_id"  @change="onUpdateWbPic(item, index, event.controlId)"></input-normal>
              <input-normal label="分享url" v-model="picItem.pic_url"  @change="onUpdateWbPic(item, index, event.controlId)"></input-normal>
            </div> -->
            <add-push-item :item="item" :index="index" :controlId="event.controlId"></add-push-item>
            <div v-if="!wbData.isSame" class="margin-left-right-16">
              <p>与转发博文对用的UI图</p>
              <add-img-con :url="item.url" picAttr="url" :index="index" :event="event" :height="100"></add-img-con>
            </div>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
    <div v-else-if="eventWbLists[0]">
      <textarea-normal label="博文内容" placeholder="请在此处输入要分享的博文内容" v-model="eventWbLists[0].text" @change="onUpdateWbItem(0)"></textarea-normal>
      <switch-normal v-model="eventWbLists[0].isPic" label="博文带图片" @change="onUpdateWbItem(0)"></switch-normal>
      <div v-if="eventWbLists[0].isPic">
        <switch-normal v-model="eventWbLists[0].isRandomPic" label="随机转发一个博文图片" @change="onUpdateWbItem(0)"></switch-normal>
        <add-push-item :item="eventWbLists[0]" :index="0" :controlId="event.controlId" class="margin-left-right-16"></add-push-item>
        <div v-if="!wbData.isSame" class="margin-left-right-16">
          <p>与转发博文对用的UI图</p>
          <add-img-con :url="eventWbLists[0].url" picAttr="url" :index="0" :event="event" :height="100"></add-img-con>
        </div>
      </div>
      <textarea-normal label="失败博文内容" placeholder="请在此处输入要分享的失败博文内容" v-model="wbData.failText" @change="onUpdateWbComponent"></textarea-normal>
    </div>
  </el-form>
</template>

<script>
  import TextareaNormal from '@/views/components/edit/TextareaNormal.vue'
  import InputNormal from '@/views/components/edit/InputNormal.vue'
  import AddPushItem from '@/views/components/add-push-item.vue'
  import SwitchNormal from '@/views/components/edit/SwitchNormal.vue'
  import AddImgCon from '@/views/components/add-img-con.vue'

  import { addUtils } from '@/views/js/add-utils'

  export default {
    mixins: [addUtils],
    components: {
      AddPushItem,
      TextareaNormal,
      SwitchNormal,
      InputNormal,
      AddImgCon,
    },
    methods: {
      onUpdateWbPic(item, index, controlId){
        // this.item.pics[picIndex].loading = false
        // this.item.pics[picIndex].pic_id = data.pic_id
        // this.item.pics[picIndex].pic_url = data.original_pic
        let params = {item, index, controlId};
        this.updateWbComponentItem(params);
      }
    }

  }
</script>
